<%@page contentType = "text/html;charset=UTF-8" %>
<%@page import="java.util.List,Servlet.birthBeen" %>
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>生日表查询结果</title>
  <style>
    table {
      width: 75%;
      border-collapse: collapse;
      margin: 0 auto;
    }

    th,
    td {
      border: 2px solid black;
      padding: 10px;
      text-align: center;
      background-color: white;
      opacity: 0.8;
    }
    body {
      background-image: url("images/img.png");
      background-size: cover;
      background-repeat: no-repeat;
      margin: 0;
      padding: 0;
    }
    h1{
      width: 50%;
      text-align : center;
      background-color: #e1a8f6;
      opacity: 0.8;
    }
    #content {
      background-color: white;
      border: 10px solid #e1a8f6;
      overflow-y: auto;
      max-height: 320px;
      margin-left: 100px;
      margin-right: 100px;
      opacity: 0.8;
    }
    .add {
      width: 300px;
      text-align : center;
      opacity: 0.8;
    }
  </style>
  <script type="text/javascript">
    function del(name){
      var flag = window.confirm("哦马吉利~曼波~你确认要删除吗");
      if(flag){
        document.location.href = "/birth/delete?name=" + name;//浏览器发送get请求
      }
    }
  </script>
</head>

<body>

  <div style="display: grid; place-items: center;">
    <h1>想起来了！wow~</h1>
    <button class="add" onclick="window.location.href='add.jsp'">新增</button>
    <button class="add" onclick="window.location.href='main.jsp'">返回</button>
    <br>
  </div>
  <div id="content">
    <table>
      <tr>
        <th>姓名</th>
        <th>年龄</th>
        <th>生日日期</th>
        <th>操作</th>
      </tr>
      <!-- 展示查询的结果 -->
      <%--拿到查询结果集--%>
      <%
        List<birthBeen> dates = (List<birthBeen>)request.getAttribute("dates");//注意这里返回的是 Object 类，需要强转为我们要用的类
        //记得要最在上面导入包
        for(birthBeen bb : dates){
          String name = bb.getName();
          int age = bb.getAge();
          String birthday = bb.getBirthday();
      %>
      <tr>
        <td><%=name%></td>
        <td><%=age%></td>
        <td><%=birthday%></td>
<%--        通过传入姓名参数给函数del发送get请求--%>
        <td><a href="javascript:void(0)" onclick="del('<%=name%>')">删除</a></td>
      </tr>
      <%
        }
      %>
      <!-- 展示查询的结果 -->
    </table>
  </div>

</body>

</html>